<?php 
namespace Admin\Controller;
use Think\Controller;
class CatController extends Controller{
	public function index(){
		$this->display();
	}

	public function cateadd(){
		if(!IS_POST){
			$this->display('cateadd');
			exit();
		}else{
			$catModel = D('Cat');
			$catModel->add($_POST);
			$this->success('添加成功','',4);
		}
	}

	public function catelist(){
		$catModel = D('Cat');
		$cat = S('catelist');
		if($cat == false){
			echo '这是数据库出来的数据';
			$catelist = $catModel->getTree();
			S('catelist',$catelist,5);
		}else{
			echo '这是缓存出来的数据';
			$catelist = $cat;
		}

		$this->assign('data',$catelist);
		$this->display();
	}

	public function catedit(){
		$catModel = D('Cat');
		if(!IS_POST){
			$cat_id = I('cat_id');
			$catInfo = $catModel->find($cat_id);
			$this->assign('info',$catInfo);
			$this->display();
		}else{
			$catModel-where('cat_id='.$_POST['cat_id'])->save($_POST);
			$this-success('修改成功','',5);
		}
	}

	public function catedel(){
		$catModel = D('Cat');
		$catModel->delete(I('get.cat_id'));
		$this->success('删除成功','',5);
	}
}